package org.jeecg.modules.demo.mall.yxsystemuserlevel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.demo.mall.entity.YxSystemUserLevel;
import org.jeecg.modules.demo.mall.entity.YxUser;
import org.jeecg.modules.demo.mall.yxsystemuserlevel.mapper.YxSystemUserLevelMapper;
import org.jeecg.modules.demo.mall.yxsystemuserlevel.service.IYxSystemUserLevelService;
import org.jeecg.modules.demo.mall.yxuser.service.IYxUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * @Description: yx_system_user_level
 * @Author: jeecg-boot
 * @Date: 2023-10-24
 * @Version: V1.0
 */
@Service
public class YxSystemUserLevelServiceImpl extends ServiceImpl<YxSystemUserLevelMapper, YxSystemUserLevel> implements IYxSystemUserLevelService {

    @Override
    public YxSystemUserLevel queryLevel(Integer uid, BigDecimal growthValue) {
        LambdaQueryWrapper<YxSystemUserLevel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.le(YxSystemUserLevel::getGrowthValue, growthValue);
        queryWrapper.orderByDesc(YxSystemUserLevel::getId);
        List<YxSystemUserLevel> yxSystemUserLevelList = this.list(queryWrapper);
        if (CollectionUtils.isEmpty(yxSystemUserLevelList)) {
            return null;
        }

        return yxSystemUserLevelList.get(0);
    }
}
